package com.xuecheng.search.controller;

import com.xuecheng.commons.model.dto.CoursePubIndexDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.CoursePubIndexVo;
import com.xuecheng.commons.model.vo.PageResponseResult;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 条件查询
     * 请求地址：POST /course-search
     * 请求参数：
     *      Body参数：CoursePubIndexDto
     *      Query参数：PageRequest
     * 响应：PageResponseResult<CoursePubIndexVo>
     */
    @PostMapping("/course-search")
    public PageResponseResult<CoursePubIndexVo> search(
                @RequestBody CoursePubIndexDto dto,
                PageRequest request) throws Exception {
        return searchService.search(dto,request);
    }

    /**
     * 根据id查询课程发布数据
     * 地址：GET /course-search/{id}
     * 返回值：ResponseResult<CoursePubIndexVo>
     */
    @GetMapping("/course-search/{id}")
    public ResponseResult<CoursePubIndexVo> findById(@PathVariable("id") Long id)
            throws IOException {
        return searchService.findById(id);
    }
}
